import { getCache } from '@/utils/cache'
import request from '@/utils/request'

enum API {
  Login = '/agent/UserLogin/login',
  GetPayList = '/agent/safe/payList',
  PayAmount = '/agent/safe/pay',
  GetOrderStatus = '/agent/safe/getPayStatus',
  Interchange = '/agent/safe/interchange',
  GetBalance = '/agent/safe/changeBalance',
  changeTakeStatus = '/agent/safe/acceptOrderStatus',
  Upload = '/agent/UserLogin/upload',
  changePassword = '/agent/safe/changePassword',
  changePayPassword = '/agent/safe/payment',
  GetSafe = '/agent/safe/index',
  SetPrompt = '/agent/safe/prompt',
  GetReminder = '/agent/newOrderReminder/Reminder',
  GetAccountChange = '/agent/accountChange/index',
  GetLoginLog = '/agent/LoginLog/index',
  GetOrderStatistics = '/agent/orderStatistics/index',
  GetPaymentStatistics = '/agent/paymentStatistics/index',
  GetUserInfo = '/agent/index',
  GetMessageIndex = '/agent/Message/index',
  EditContact = '/agent/safe/contact',
  GetGoogleIndex = '/agent/google/index',
  GoogleEdit = '/agent/google/edit',
  GoogleValidate = '/agent/google/validation'
}

export function GoogleValidateApi(data: { type: string; googleCode: string }) {
  return request({ url: API.GoogleValidate, method: 'post', data })
}

export function GoogleEditApi(data: { use_google: string; google_token: string }) {
  return request({ url: API.GoogleEdit, method: 'post', data })
}

export function GetGoogleIndexApi() {
  return request({ url: API.GetGoogleIndex, method: 'post' })
}

export function EditContactApi(contact: string) {
  return request({ url: API.EditContact, method: 'post', data: { contact } })
}

export function GetMessageIndexApi(data: { page: number }) {
  return request({
    url: API.GetMessageIndex,
    method: 'post',
    data
  })
}

export function GetUserInfoApi() {
  return request({
    url: API.GetUserInfo,
    method: 'post'
  })
}

export function GetPaymentStatisticsApi(data: { page: number }) {
  return request({
    url: API.GetPaymentStatistics + `?page=${data.page}`,
    method: 'post',
    data
  })
}

export function GetOrderStatisticsApi(data: { page: number }) {
  return request({
    url: API.GetOrderStatistics + `?page=${data.page}`,
    method: 'post',
    data
  })
}

export function GetLoginLogApi(data: { page: number }) {
  return request({
    url: API.GetLoginLog + `?page=${data.page}`,
    method: 'post',
    data
  })
}

export function GetAccountChangeApi(data: { page: number }) {
  return request({
    url: API.GetAccountChange + `?page=${data.page}`,
    method: 'post',
    data
  })
}

export function GetReminderApi(data: { type: string }) {
  return request({
    url: API.GetReminder,
    method: 'post',
    data
  })
}

export function SetPrompt(data: { prompt: string }) {
  return request({
    url: API.SetPrompt,
    method: 'post',
    data
  })
}

export function GetSafeApi() {
  return request({
    url: API.GetSafe,
    method: 'post'
  })
}

export function LoginApi(username: string, password: string, code: string, google: string) {
  return request({
    url: API.Login,
    method: 'post',
    data: {
      username,
      password,
      keep: '1',
      code,
      google
    },
    headers: {
      'x-uuid': getCache('x-uuid')
    }
  })
}

export function GetPayListApi() {
  return request({
    url: API.GetPayList,
    method: 'post'
  })
}

export function PayAmountApi(data: { id: number; amount: number }) {
  return request({
    url: API.PayAmount,
    method: 'post',
    data
  })
}

export function GetOrderStatusApi(order: string) {
  return request({
    url: API.GetOrderStatus,
    method: 'post',
    data: {
      order
    }
  })
}

export function InterchangeApi(data: { payment_address: string; payment: string; amount: number }) {
  return request({
    url: API.Interchange,
    method: 'post',
    data
  })
}

export function GetBalanceApi() {
  return request({
    url: API.GetBalance,
    method: 'post'
  })
}

export function changeTakeStatusApi(data: { status: string }) {
  return request({
    url: API.changeTakeStatus,
    method: 'post',
    data
  })
}

export function UploadApi(file: any, analysisSrc: number) {
  const formData = new FormData()
  formData.append('file', file)
  if (analysisSrc == 1) formData.append('analysis', '1')
  return request({
    url: API.Upload,
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data: formData
  })
}

export function changePasswordApi(data: { oldPassword: String; newPassword: String }) {
  return request({
    url: API.changePassword,
    method: 'post',
    data
  })
}

export function changePayPasswordApi(data: { oldPassword: String; newPassword: String }) {
  return request({
    url: API.changePayPassword,
    method: 'post',
    data
  })
}
